<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // Promise 解决问题是回调地狱
    // Promise三个状态: 
    // pending 等待状态默认
    // fulfilled Promise的resolve方法确定
    // failed  Promise的reject方法确定
    // Promise的状态一旦确定，就不可改变

    function fn() {
      return new Promise((resolve, reject) => {
        setTimeout(() => {
          // resolve('123')
          reject('错误')
        }, 2000)
      })
    }
    fn().then(res => {
      console.log(res)
    }).catch(err => {
      console.log(err)
    })
  </script>
</body>

</html>